<?php

namespace common\models;
/**
 * This is the model class for table "{{%category}}".
 *
 * @property integer $id
 * @property integer $pid
 * @property string $cname
 * @property string $desc
 *
 * @property Article[] $articles
 */
class Category extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%category}}';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['pid'], 'integer'],
            [['cname', 'desc'], 'string', 'max' => 255],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => '分类id',
            'pid' => '父类id',
            'cname' => '分类名称',
            'desc' => '分类描述',
        ];
    }

    /**
     *@return category
     *@by fangkeke
     */
    static public function getAllCategory()
    {
        $cate = self::find()->asArray()->all();
        return FormatCategory::unlimitedForLevel($cate);
    }

    /**
     *@return array
     */
    static public function getAllFather($where)
    {
        return Category::find()->where($where)->asArray()->all();
    }
}
